package com.prs.crm.dao.cqunicom.impl;


import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cqunicom.ServicesDao;
import com.prs.crm.dao.impl.BaseDaoImpl;

import com.prs.crm.domain.cqunicom.Services;
import com.prs.crm.domain.cqunicom.ServicesType;

/**
 * @author  WangTing
 *
 * 创建时间：2011-3-4 
 * 
 */
public class ServicesDaoImpl extends BaseDaoImpl<Services> implements ServicesDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Services> getAllServices() {
		// TODO Auto-generated method stub
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(Services.class);
				return criteria.list();
			}
			
		});
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Services> getServicesBytype(final String types) {
		// TODO Auto-generated method stub
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(Services.class);
				criteria.add(Restrictions.eq("type", types));
				return criteria.list();
			}
			
		});
	}
	@Override
	public List<Services> getByStyle(final ServicesType servicesType) {
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				Criteria criteria = arg0.createCriteria(Services.class);
				criteria.add(Restrictions.eq("servicesType", servicesType));
				return criteria.list();
			}
			
		});
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Services> getByWorkPattern(final String workPattern) {
		// TODO Auto-generated method stub
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(Services.class);
				criteria.add(Restrictions.eq("workPattern", workPattern));
				return criteria.list();
			}
			
		});
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Services> getBySheet(final String sheets) {
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				Criteria criteria = arg0.createCriteria(Services.class);
				criteria.add(Restrictions.eq("simplename", sheets));
				return criteria.list();
			}
			
		});
	}
	@SuppressWarnings("unchecked")
	@Override
	public List<Services> getByall() {
		return (List<Services>) this.getHibernateTemplate().execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				Criteria criteria = arg0.createCriteria(Services.class);
				criteria.add(Restrictions.eq("noteHand", "1"));
				return criteria.list();
			}
			
		});
	}
	@Override
	public void saveOrUpservices(Services s) {
		this.getHibernateTemplate().saveOrUpdate(s);
	}

	

}
